package com.jxc.wiki.controller;

import com.jxc.wiki.entity.Comment;
import com.jxc.wiki.interceptor.LoginInterceptor;
import com.jxc.wiki.request.CommentSaveParamReq;
import com.jxc.wiki.response.CommentQueryParamResp;
import com.jxc.wiki.response.CommonResp;
import com.jxc.wiki.response.StatisticParamCommentResp;
import com.jxc.wiki.service.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/comment")
public class CommentController {

    private static final Logger LOG = LoggerFactory.getLogger(LoginInterceptor.class);

    @Resource
    CommentService commentService;

    @PostMapping("/save")
    public CommonResp<Comment> save(@RequestBody CommentSaveParamReq req){
        LOG.info("/comment/save接口controller里的CommentSaveReq：{}",req);
        CommonResp<Comment> commentCommonResp = new CommonResp<>();
        commentService.saveComment(req);
        return commentCommonResp;
    }

    @GetMapping("/list/{docName}")
    public CommonResp<List<CommentQueryParamResp>> getComment(@PathVariable String docName){
        LOG.info("后端接口接受到的getComment的请求参数：{}",docName);
        CommonResp<List<CommentQueryParamResp>> commonResp = new CommonResp<>();
        commonResp.setContent(commentService.getComment(docName));
        return commonResp;
    }

    @GetMapping("getCommentCount")
    public CommonResp<StatisticParamCommentResp> getCommentCount(){
        StatisticParamCommentResp resp = commentService.getStatisticComment();
        CommonResp<StatisticParamCommentResp> commonResp = new CommonResp<>();
        commonResp.setContent(resp);
        return commonResp;
    }
}
